<?php

namespace Model\CourseBundle\Controller;

use Model\CourseBundle\Setting\CourseSetting;
use Model\CourseCategoryBundle\Model\CourseCategoryModel;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

use Symfony\Component\HttpFoundation\Request;
use Base\BaseController;
use Model\CourseBundle\Entity\Course as Entity;

/**
 * @route("/admin/")
 */
class CourseAdminController extends BaseController
{

    /**
     * @route("Course/add",name="CoursePreAdd")
     */
    public function add()
    {
        die("请到前台添加课程");
        //通用代码
        $this->setSetting(new CourseSetting($this->getDoctrine()->getManager()));
        return $this->comAdd();
    }

    /**
     * @route("Course/add/do",name="CourseDoAdd")
     *
     * @Method({"GET", "POST"})
     */
    public function doAdd(Request $request)
    {
        die("请到前台添加课程");
        //私有代码
        $entity = new Entity();
        $entity->setAddTime(time());

        //通用代码
        $this->setSetting(new CourseSetting($this->getDoctrine()->getManager()));
        return $this->comDoAdd($request,$entity);
    }

    /**
     * @route("Course/edit/{id}",name="CoursePreEdit")
     */
    public function edit(Entity $entity)
    {
        die("不建议管理员修改用户课程");
        $this->setSetting(new CourseSetting($this->getDoctrine()->getManager()));
        return $this->comEdit($entity);
    }

    /**
     * @route("Course/edit/{id}/do",name="CourseDoEdit")
     *
     * @Method({"GET", "POST"})
     */
    public function doEdit(Request $request,Entity $entity)
    {
        die("不建议管理员修改用户课程");
        $this->setSetting(new CourseSetting($this->getDoctrine()->getManager()));
        return $this->comDoEdit($request,$entity);
    }

    /**
     * @route("Course",name="CourseLists")
     */
    public function lists()
    {
        //私有部分
        $CourseCategoryModel = new CourseCategoryModel($this->getDoctrine());
        $classes = $CourseCategoryModel->getAllCourseCategoryTree();
        $tools = array("category"    => $classes,);

        //通用部分
        $this->setSetting(new CourseSetting($this->getDoctrine()->getManager()));
        return $this->comLists($tools);
    }


    /**
     * @route("Course/tools",name="CourseTools")
     */
    public function tools(Request $request)
    {
        $this->setSetting(new CourseSetting($this->getDoctrine()->getManager()));
        return $this->comTools($request);
    }

}
